import { axios } from 'taro-axios';
import {toast} from '@/u';

const instance = axios.create({
    baseURL: process.env.URL,
    timeout: 1000 * 120,
});

instance.interceptors.request.use(config =>{
  toast.show('加载中...', 'loading');
    return config;
});

instance.interceptors.response.use(res=>{
    if(res.status !== 200 || res.data.code !== 200){
        if(res.data.messages)toast.show(res.data.messages);
        return Promise.reject(res.data);
    }else{
        toast.hide();
        return Promise.resolve(res.data);
    }
}, err => {
    toast.show('非常抱歉，网络出错了！');
    return Promise.reject();
})
export default instance;
